import { Injectable } from '@angular/core';
import { HttpClient } from '../../../providers/httpClient';
import { Config } from '../../../providers/config';
import _ from "lodash";

@Injectable()
export class CashService {
	constructor(
		public httpClient: HttpClient,
		public config: Config,
	) { }

	getCashQueryData(fundCode, condition) {
    /*var postBody = {
      "module": "KSB",
      "method": "IPM_004_0010",
      "format": "json",
      "params": {
        "vc_user": "zqx",
        "vc_rpt_no": condition["dataStyle"],
        "c_portfolio_type": "1",
        "l_portfolio_no": "100028",
        "l_begin_date": condition.startDate.replace(/-/g, ""),
        "l_end_date": condition.endDate.replace(/-/g, ""),
        "l_plan_no": "-1"
      }
    };*/

	  let postBody = {
	    "module": "OAServer",
      "method": "getCashQueryData",
      "params": {
        fund_code: fundCode,
        startDate: condition.startDate.replace(/-/g, ""),
        endDate: condition.endDate.replace(/-/g, ""),
        dataStyle: condition.dataStyle
      }
    };

	  console.log(postBody);

    return this.httpClient.post(postBody, {
      isShowLoading: false,
      timeout: 120 * 1000
    });
  }

  getCashTARedemptionDetail(params) {
	  let postBody = {
	    "module": "OAServer",
      "method": "getCashTARedemptionDetail",
      "params": params
    };

	  return this.httpClient.post(postBody, {
	    isShowLoading: true
    })
  }

  /**
  * 获取报表样式选项
  */
  getTableStyle() {
    let postBody = {
	    "module": "OAServer",
      "method": "getTableStyle",
      "params": {}
    };
	  return this.httpClient.post(postBody, {
	    isShowLoading: true
    })
  }

  /**
   * 获取现金流批量数据
   */
  getCashQueryBatchData(fundCode, condition) {
    let postBody = {
      "module": "OAServer",
      "method": "getCashQueryBatchData",
      "params": {
        fund_code: fundCode,
        startDate: condition.startDate.replace(/-/g, ""),
        endDate: condition.endDate.replace(/-/g, ""),
        dataStyle: condition.dataStyle
      }
    };

    console.log( 'postBody', postBody)
    return this.httpClient.post(postBody, {
      isShowLoading: false,
      timeout: 120 * 1000
    });
  }
}
